
import React, {useState,useEffect} from 'react';

function FunctionComponent(props) {
    const [date,setDate] = useState(new Date())
    useEffect(()=>{
        //相当componentDidMount与componentWillUnmount、componentDidUpdate
        console.log('useEfftect')
        const timer = setInterval(() => {
            setDate(new Date())
        }, 1000);
        return ()=>clearInterval()
    },[]/*添加依赖项*/)
    return (
        <div>
           <h3>FunctionComponent</h3>
           <p>{date.toLocaleTimeString()}</p>
        </div>
    );
}

export default FunctionComponent;